package com.neusoft.actor.controller;

import com.neusoft.actor.po.Message;
import com.neusoft.actor.po.ResponseBean;
import com.neusoft.actor.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/MessageController")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/saveMessage")
    public ResponseEntity<Map<String, Object>> saveMessage(@RequestBody Message message) {
        Map<String, Object> response = new HashMap<>();
        try {
            messageService.saveMessage(message);
            response.put("status", 200);
            response.put("msg", "预约成功");
        } catch (Exception e) {
            response.put("status", 500);
            response.put("msg", "预约失败: " + e.getMessage());
        }
        return ResponseEntity.ok(response);
    }

    @GetMapping("/getMessagesByCareTakerId")
    public ResponseBean<List<Message>> getMessagesByCareTakerId(Integer careTakerId) {
        return messageService.getMessagesByCareTakerId(careTakerId);
    }

    @PostMapping("/emergency")
    public ResponseBean<Integer> emergency(@RequestBody Message message) {
        return messageService.emergency(message);
    }
}
